package biz.bbtec.sbm.email.send;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import biz.bbtec.sbm.email.factory.EmailAlarmFactory;
import biz.bbtec.sbm.email.service.EmailAlarmService;
import biz.bbtec.sbm.issuetracking.bean.TaskBean;
import biz.bbtec.sbm.user.bean.UserBean;

public class ss extends ActionSupport {

	private List<UserBean> userlist;
	private TaskBean task = new TaskBean();

	public TaskBean getTask() {
		return task;
	}

	public void setTask(TaskBean task) {
		this.task = task;
	}

	public List<UserBean> getUserlist() {
		return userlist;
	}

	public void setUserlist(List<UserBean> userlist) {
		this.userlist = userlist;
	}

	public void Send() {
		// 这个类主要是设置邮件
		MailSenderInfo mailInfo = new MailSenderInfo();
		mailInfo.setMailServerHost("smtp.qq.com");
		mailInfo.setMailServerPort("25");
		mailInfo.setValidate(true);
		mailInfo.setUserName("sbm-service@bbtec.biz");
		mailInfo.setPassword("bb123456");// 您的邮箱密码
		mailInfo.setFromAddress("sbm-service@bbtec.biz");
		mailInfo.setToAddress("sbm-service@bbtec.biz");
		mailInfo.setSubject("你好");
		mailInfo.setContent("再见");
		// 这个类主要来发送邮件
		SimpleMailSender sms = new SimpleMailSender();
		sms.sendHtmlMail(mailInfo);// 发送html格式
	}

	public String NoticeSend() throws Exception {
		MailSenderInfo mailInfo = new MailSenderInfo();
		mailInfo.setMailServerHost("smtp.qq.com");
		mailInfo.setMailServerPort("25");
		mailInfo.setValidate(true);
		mailInfo.setUserName("sbm-service@bbtec.biz");
		mailInfo.setPassword("bb123456");// 您的邮箱密码
		mailInfo.setFromAddress("sbm-service@bbtec.biz");

		Map session = ActionContext.getContext().getSession();
		UserBean user = (UserBean) session.get("user");
		
		EmailAlarmService service = EmailAlarmFactory.getInstance().createEmailAlarmService();
		for (int i = 0; i < userlist.size(); i++) {
			UserBean userbean = service.User(userlist.get(i).getUserid());
			if(userbean.getEmail() == null){
				continue;
			}
			mailInfo.setToAddress(userbean.getEmail());
			mailInfo.setSubject("邀请通知");
			String context = "您好：\n" + user.getName() + "邀请您加入"
					+ task.getName() + "该项目，请您尽快登录sbm系统处理！";
			mailInfo.setContent(context);
			SimpleMailSender sms = new SimpleMailSender();
			sms.sendHtmlMail(mailInfo);// 发送html格式
		}

		return SUCCESS;
	}
}
